//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    temp:"4",
    temperature:"-1/10℃",
    type:"晴",
    city:"成都",
    date:"2000-01-01",
    direction:"无持续风向微风级",
    condition:"10",
    futureArray:"[]",
    /**当前温度 */
    currTemperature: 0,
    /*上次更新时间 */
    lastFlashTime: '无数据',
    /**今日温度 */
    todayTemperature: '无数据',
    /**今日天气 */
    todayWeather: '无数据',
    /** 穿衣指数*/
    dressingIndex: '无数据',
    /**紫外线强度 */
    uvIndex: '无数据',
    /**洗车指数 */
    washIndex: '无数据',
    /**旅游指数 */
    travelIndex: '无数据',
    /**晨练指数 */
    exerciseIndex: '无数据',
    /**未来7天天气数据 */
    futureData: '',
  


  },
  
  //事件处理函数
  bindViewTab: function() {
    wx.navigateTo({
      url: '../test1/test1'
    })
  },
  switchBtn: function() {
    wx.switchTab({
      url: '../main/main',
      success: function() {

      },
      fail: function() {

      },
      complete () {

      }
    })
  },
  onLoad: function () {
    wx.request({
      url: 'http://v.juhe.cn/weather/index?',
      data: {
      
        "cityname": '成都',
        "key": 'c89a8af447fcef4d3195f8c5d4e1c172'
      },
      success: res => {
        console.log(res)
        this.getIndex(res)
        var result = res;
        var test1 = JSON.stringify(result);
        console.log(res.data.result.today.date_y)
        this.setData({
          city: res.data.result.city,
          temp: res.data.result.sk.temp,
          temperature: res.data.result.today.temperature,
          type: res.data.result.today.weather,
          direction: res.data.result.today.wind,
          date: res.data.result.today.date_y,
          futureArray: res.data.result.future,
        })
      }
    })
    
  },
  
  getIndex: function (res) {
    let dressingIndex = res.data.result.today.dressing_index //穿衣指数
    let uvIndex = res.data.result.today.uv_index //紫外线强度
    let washIndex = res.data.result.today.wash_index //洗车指数
    let travelIndex = res.data.result.today.travel_index //旅游指数
    let exerciseIndex = res.data.result.today.exercise_index //晨练指数
    this.setData({
      dressingIndex: dressingIndex,
      uvIndex: uvIndex,
      washIndex: washIndex,
      travelIndex: travelIndex,
      exerciseIndex: exerciseIndex
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
  
})


